﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //第1种方式
            var sqlCon = "server = BF-202003151143\\sqlexpress; database = Ppz; uid = sa; pwd = 3578520r";
            SqlConnection sqlConnection = new SqlConnection(sqlCon);

            sqlConnection.Open();

            

            SqlCommand sqlCommand = new SqlCommand("select * from commodity", sqlConnection);
            var reade = sqlCommand.ExecuteReader();

            Console.WriteLine("{0}\t\t{1}\t{2}\t{3}\t{4}\t{5}", "商品ID",
                "商品名", "价格", "库存", "厂家ID", "类型ID");
            while (reade.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
                    reade["commodityId"], reade["commodityName"], reade["price"],
                    reade["inventory"],reade["FactoryId"], reade["genreId"]);
            }

            sqlConnection.Close();
            

        }
    }
}
